package day017.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExceptionDemo1 {
    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger("ExceptionDemo1");

        try {
            printInfo("熊大", 0);
        } catch (NullPointerException e) {
            System.out.println("处理空值异常");
        } catch (AgeOutOfBoundsExceptions e) {
            System.out.println("处理年龄超出18-50范围异常");
            logger.error(e.getMessage());
        } catch (RuntimeException e) {
            System.out.println("处理其他运行时异常");
        } catch (Exception e) {
            System.out.println("可以处理任何异常");
        }
    }

    public static void printInfo(String name, int age) {
        if (name == null || "".equals(name)) {
            throw new NullPointerException("传递的姓名不能为空");
        }

        if (age < 18 || age > 50) {
            throw new AgeOutOfBoundsExceptions("传递的值为：" + age + "，年龄必须在18-50之间");
        }

        System.out.println("姓名：" + name);
        System.out.println("年龄：" + age);
    }
}

